package ar.edu.unq.wannaplay.ws;

import java.util.LinkedList;
import java.util.List;

import javax.jws.WebService;

import org.springframework.stereotype.Controller;

import ar.edu.unq.wannaplay.dtos.SkillDTO;
import ar.edu.unq.wannaplay.employee.Experience;
import ar.edu.unq.wannaplay.employee.PersonalData;
import ar.edu.unq.wannaplay.exceptions.EmailSyntaxException;
import ar.edu.unq.wannaplay.services.EmployeeService;

@Controller
@WebService(endpointInterface = "ar.edu.unq.wannaplay.ws.EmployeeWebService")
public class EmployeeWebServiceImpl implements EmployeeWebService {

    private EmployeeService employeeService;

    @Override
    public String addEmployee(final String name, final String id, final String surname, final String telephone,
            final String university, final String email, final String address, final String town) {
        PersonalData data = new PersonalData(name, surname, id, address, town, telephone, email, university);
        try {
            employeeService.saveEmployee(data, "", new LinkedList<SkillDTO>());
        } catch (EmailSyntaxException e) {
            System.out.println("LA CAGASTE!!! ARREGLA EL MAIL!!");
        }
        return id;
    }

    public void setEmployeeService(final EmployeeService employeeService) {
        this.employeeService = employeeService;
    }

    public EmployeeService getEmployeeService() {
        return employeeService;
    }

    @Override
    public String addMediumSkillToEmployee(final String id, final String skillName) {
        this.addSkillToEmployee(id, skillName, Experience.MEDIUM);
        return skillName;
    }

    private void addSkillToEmployee(final String id, final String skillName, final Experience experience) {
        List<SkillDTO> skills = this.getEmployeeService().findEmployeeDTOByDNI(id).getSkills();
        SkillDTO newSkill = new SkillDTO(experience, skillName);
        skills.add(newSkill);
        this.getEmployeeService().updateEmployee(id, skills);

    }

}
